﻿/**
 * Created with JetBrains WebStorm.
 * User: kane
 * Date: 13-2-27
 * Time: 下午6:57
 * To change this template use File | Settings | File Templates.
 */
var User = require('../bean/DBuser');

exports.main = function(args,req, res){
    args = args[0];
//db:[{m:"save",user:{name:"a",password:"b"}}]
    if(args.m=='save'){
        var user = new User(args.user);
        user.save(function(err){
            if(err){
                res.render('info', { title: 'Express',info:err });
            }else{
                res.render('info', { title: 'Express',info:'成功' });
            }
        });
    }else{
        //db:[{m:"read",name:"a"}]
        User.get(args.name,function(err,user){
            if(err){
                res.render('info', { title: 'Express',info:err });
                return;
            }

            if(!user){
                res.render('info', { title: 'Express',info:'用户不存在！' });
                return;
            }
            res.render('info', { title: 'Express',info:user.password });
        });
    }
};